package com.gee.spring.boot.rpf.client.calculator.factor;

import com.gee.spring.boot.rpf.client.calculator.Calculator;
import com.gee.spring.boot.rpf.client.BaseClientResponse;
import com.gee.spring.boot.rpf.common.constant.ClientConstant;
import com.gee.thread.flow.common.result.ExecuteState;
import org.springframework.stereotype.Component;

/**
 * desc:
 *
 * @author gee wrote on  2021-02-06 14:58:25
 */
@Component
public class SimpleFactorCalculator implements Calculator {

    @Override
    public Object calculate(ExecuteState executeState, BaseClientResponse response, Class factorType,
                            Object ...otherParam){
        if (ExecuteState.SUCCESS != executeState){
            return getClientExceptionFactor(factorType);
        }
        if (! ClientConstant.CLIENT_SUCCESS_CODE.equals(response.getCode())){
            return getResponseCodeNotSuccessFactor(factorType);
        }
        Object result = null;
        if (otherParam == null || otherParam.length == 0){
            return getParamNullFactor(factorType);
        }
        try {
            result = getNormalFactor(factorType, otherParam[0]);
        } catch (Exception e) {
            result = getCalculateExceptionFactor(factorType);
        }
        return result;
    }
}
